package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.annotation.Log;
import com.qf.entity.LogQueryDTO;
import com.qf.entity.SysLog;
import com.qf.service.SysLogService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@RestController
@RequestMapping("/sys")
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;
    @Log(value = "查看系统日志", type = "查看")

    @GetMapping("/sysSkuLog")
    public R sysLog (@ModelAttribute LogQueryDTO logQueryDTO) {
        System.out.println("Received parameters: " + logQueryDTO);
        if (logQueryDTO == null) {
            System.out.println("logQueryDTO is null!");
        } else {
            System.out.println("page: " + logQueryDTO.getPage());
            System.out.println("size: " + logQueryDTO.getSize());
            System.out.println("search: " + logQueryDTO.getSearch());
            System.out.println("startDate: " + logQueryDTO.getStartDate());
            System.out.println("endDate: " + logQueryDTO.getEndDate());
        }
        PageHelper.startPage(logQueryDTO.getPage(), logQueryDTO.getSize());
        List<SysLog> list = sysLogService.syslog(logQueryDTO);
        PageInfo<SysLog> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    @PostMapping("/deleteLog")
    @Log(value = "删除系统日志", type = "删除")
    public R deleteLog (@RequestBody List<String> ids) {
        ids.forEach(System.out::println);
        boolean ok = sysLogService.deleteLog(ids);
        if (ok) {
            return R.ok();

        }
        return R.fail();
    }

}
